package com.cheyunkeji.er.view.evaluate;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.view.AbsDialog;
import com.cheyunkeji.er.view.MyRadioGroup;
import com.cheyunkeji.er.view.STextView;

/**
 * Created by Michael on 2017/4/5 21:42.
 */

public class CarProblemStateSelectDialog extends AbsDialog implements View.OnClickListener {

    private STextView tvConfirm, tvCancel;
    private MyRadioGroup myRadioGroup;
    private Context context;
    private RadioButton rbNone,rbBian,rbQu,rbHuan,rbHan,rbZhou,rbXiu ;
    private Object mTag = null ;

    private onResultSelectedListener listener;

    /**
     * 是否点击则取消，默认为true
     */
    private boolean clickCancelable = true;

    public CarProblemStateSelectDialog(Context context, boolean clickCancelable, onResultSelectedListener listener) {
        super(context, R.style.dialog_style_dim_3);
        this.context = context;
        this.listener = listener;
        this.clickCancelable = clickCancelable;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.er_car_problem_state_select);

        findViews();
        setListener();
        initView();

    }

    private void findViews() {

        init();
        tvConfirm = (STextView) findViewById(R.id.tv_confirm);
        tvCancel = (STextView) findViewById(R.id.tv_cancel);
        myRadioGroup = (MyRadioGroup) findViewById(R.id.mrg_radio_group);

        rbNone = (RadioButton) findViewById(R.id.rb_none);
        rbBian = (RadioButton) findViewById(R.id.rb_bian);
        rbQu = (RadioButton) findViewById(R.id.rb_qu);
        rbHuan = (RadioButton) findViewById(R.id.rb_huan);
        rbHan = (RadioButton) findViewById(R.id.rb_han);
        rbZhou = (RadioButton) findViewById(R.id.rb_zhou);
        rbXiu = (RadioButton) findViewById(R.id.rb_xiu);

    }

    private void setListener() {

        tvConfirm.setOnClickListener(this);
        tvCancel.setOnClickListener(this);

    }

    private void initView() {

        myRadioGroup.setCheckWithoutNotif(R.id.rb_none);
    }

    public void setSelectedButton(int btnId){
        myRadioGroup.setCheckWithoutNotif(btnId);
    }

    public void setTag(Object tag){
        this.mTag = tag ;
    }
    public Object getTag(){
        return mTag ;
    }

    @Override
    public void onClick(View v) {

        if (clickCancelable) dismiss();

        switch (v.getId()) {
            case R.id.tv_cancel:
                listener.onCancel();
                break;
            case R.id.tv_confirm:
                listener.onConfirm(myRadioGroup.getCheckedRadioButtonId());
                break;

            default:
                break;
        }

    }


    public interface onResultSelectedListener {

        void onConfirm(int checkedRadioButtonId);

        void onCancel();
    }
}
